﻿
$inputFile = "UserData.json"
$outputFile = "output.json"


$jsonText = Get-Content $inputFile -Encoding UTF8 | Out-String

$jsonText = $jsonText -replace '\ufffd', ''


try {
    $jsonData = $jsonText | ConvertFrom-Json
} catch {
    Write-Host "JSON解析失败：$_"
    exit 1
}


$uniqueEntries = @{}
foreach ($item in $jsonData) {
    $item | Add-Member -NotePropertyName "logintype" -NotePropertyValue 1 -Force
    $uniqueEntries[$item.Wxid] = $item
}

$finalData = $jsonData | 
    ForEach-Object { $_.Wxid } | 
    Select-Object -Unique | 
    ForEach-Object { $uniqueEntries[$_] }

$utf8NoBom = [System.Text.UTF8Encoding]::new($false)
[System.IO.File]::WriteAllLines($outputFile, ($finalData | ConvertTo-Json -Depth 100), $utf8NoBom)

Write-Host "处理完成！输出文件: $outputFile"